home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / kh_gdi.zip / KH_GDI / BGIPAINT.H < prev    next >
C/C++ Source or Header  |  1996-05-24  |  5KB  |  167 lines

  1. #ifndef __BGI_PAINT_H_
  2. #define __BGI_PAINT_H_
  3.  
  4. //#include <owl\owlpch.h>
  5. //#pragma hdrstop
  6. #include <windows.h>
  7. #include "kh_gdi\paint.h"
  8. #include "general\simple.h"
  9. //////////////// Common color ref. and fill code ////////////////////////
  10. /*
  11. #ifndef RGB
  12.  
  13. #define COLORREF unsigned long
  14. #define BYTE uchar
  15. #define WORD unsigned short
  16. #define DWORD unsigned long
  17.  
  18. #define RGB(r,g,b)          ((COLORREF)(((BYTE)(r)|((WORD)(g)<<8))|(((DWORD)(BYTE)(b))<<16)))
  19.  
  20. #endif RGB
  21. */
  22. ////////////////////////////////////////////////////////////////////////////
  23. #define SOLID_FILL              1
  24. #define SOLID_LINE              PS_SOLID
  25. #define DASHED_LINE             PS_DASH
  26. #define DOTTED_LINE             PS_DOT
  27. #define CENTER_LINE             PS_DASHDOT
  28.  
  29. // Do not use HS_BDIAGONAL, HS_FDIAGONAL, HS_VERTICAL, HS_HORIZONTAL
  30. // HS_CROSS and HS_DIAGCROSS !!!
  31. #define LINE_FILL               0
  32. #define HATCH_FILL              2
  33. #define SLASH_FILL              3
  34. #define XHATCH_FILL             4
  35. #define BKSLASH_FILL            5
  36. #define LTSLASH_FILL            6
  37.  
  38. #define LEFT_TEXT     0
  39. #define CENTER_TEXT   1
  40. #define RIGHT_TEXT    2
  41. #define BOTTOM_TEXT   0
  42. #define TOP_TEXT      2
  43.  
  44. ////////////////////////////////////////////////////////////////////////////
  45. #define HS_SOLID                SOLID_FILL
  46. //////////////////////////////////////////////////////////
  47. enum COLORS { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
  48.      DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA,
  49.      YELLOW, WHITE };
  50. ////////////////////////////////////////////////////////////////////////////
  51. struct color_to_16
  52.      {
  53.      int color;
  54.      COLORREF colorref;
  55.      };
  56.  
  57. //extern color_to_16 _export tricolors[16];
  58. static color_to_16 tricolors[16] =
  59.      {   { BLACK, 0 },
  60.           { BLUE, RGB(0, 0, 128) },
  61.           { GREEN, RGB(0, 128, 0) },
  62.           {  CYAN, RGB(0, 128, 128) },
  63.           {  RED, RGB(128, 0, 0) },
  64.           { MAGENTA, RGB(74, 23, 74) },
  65.           { BROWN, RGB(128, 64, 64) },
  66.           { LIGHTGRAY, RGB(128, 128, 128) },
  67.           { DARKGRAY, RGB(64, 64, 64) },
  68.           { LIGHTBLUE, RGB(0, 0, 255) },
  69.           { LIGHTGREEN, RGB(0, 255, 0) },
  70.           { LIGHTCYAN, RGB(0, 255, 255) },
  71.           { LIGHTRED, RGB(255, 0, 0) },
  72.           { LIGHTMAGENTA, RGB(255, 0, 255) },
  73.           { YELLOW, RGB(255,255,30) },
  74.           { WHITE, RGB(255, 255, 255) }
  75.      };
  76. ////////////////////////////////////////////////////////////////////////////
  77. //#define WIN31
  78. /*
  79. #undef COLORREF
  80. #undef BYTE
  81. #undef WORD
  82. #undef DWORD
  83. */
  84. //#undef RGB
  85.  
  86. struct _export To_Paint
  87.      {
  88.      int PenSize;
  89.      int PenStyle;
  90.      COLORREF color;
  91.  
  92.      int pattern_num;
  93.      int fill_color;
  94.      COLORREF BrushColor;
  95.  
  96.      HDC DC;
  97.      /////////////////////////////////
  98.      To_Paint() { pattern_num = SOLID_FILL; PenSize = 1; PenStyle = PS_SOLID;
  99.          color = RGB(0,0,0); BrushColor = RGB(0,0,0); }
  100.      /////////////////////////////////
  101.      int getx() { POINT p; ::GetCurrentPositionEx(DC, &p); return p.x; }
  102.      int gety() { POINT p; ::GetCurrentPositionEx(DC, &p); return p.y; }
  103.      COLORREF getcolorref() { return color; }
  104.      int getcolor(COLORREF col);
  105.      int getcolor() { return getcolor(color); }
  106.  
  107.      void setcolor(int r, int g, int b)    { color = RGB(r,g,b); }
  108.      void setcolor(int c)
  109.     { color = tricolors[c].colorref; }
  110.  
  111.      void putpixel(int x, int y) { ::SetPixel(DC, x, y, getcolorref()); }
  112.      void setlinestyle(int width, int style)
  113.     { PenSize = width; PenStyle = style; }
  114.     void setlinestyle(int style, unsigned int, int width)
  115.     { PenSize = width; PenStyle = style; }
  116.  
  117.     void setfillstyle(int style, int col)
  118.     {
  119.     pattern_num = style;
  120.     fill_color = col;
  121.     BrushColor = tricolors[col].colorref;
  122.     }
  123.     void setfillstyle(int style, COLORREF col)
  124.     {
  125.     pattern_num = style;
  126.     BrushColor = col;
  127.     }
  128.  
  129.     void moveto(int x, int y) { ::MoveTo(DC, x, y); }
  130.     void lineto(int x, int y);
  131.     void fillpoly(int numpoints, int* polypoints);
  132.     void drawpoly(int numpoints, int far* points);
  133.     };
  134.  
  135. /////////////////////////////////////////////////////////////////////////////
  136. /*  KH_Paint class could draw graphics primitives using different libraries,
  137.      zoom, scroll, rotate (including complex rotations) and so on.
  138. */
  139.  
  140. struct _export KH_Paint : public To_Paint, public Paint
  141.      {
  142.     KH_Paint();
  143.  
  144.         int getx();
  145.         int gety();
  146.     loc get_CP();
  147.     void putpixel(int x, int y);
  148.     void line(int xstart, int ystart, int xend, int yend)
  149.         { moveto(xstart, ystart); lineto(xend, yend); }
  150.  
  151.     void lineto(int x, int y);
  152.     void moveto(int x, int y);
  153.     void circle(int x, int y, int radius)
  154.             { ellipse(x, y, 0, 360, radius, radius); }
  155.     void ellipse(int x, int y, int stangle, int endangle, int xr, int yr);
  156.     void rectangle(int left, int top, int right, int bottom);
  157.     void drawpoly(int numpoints, int far* points);
  158.     void fillpoly(int numpoints, int far* points)
  159.         { int f = fill; fill = ON; drawpoly(numpoints, points);
  160.          fill = f; }
  161.     void bar3d(int l, int t, int r, int b, int d, int top);
  162.     virtual void outtext(char* str, int dir = 0);
  163.     void set_fill(int state) { fill = state; }
  164.     };
  165.  
  166. #endif __BGI_PAINT_H_
  167.